package com.zoke.daycarpool.adapter;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TextView;

import com.zoke.daycarpool.R;
import com.zoke.daycarpool.domain.Address;
import com.zoke.support.base.BaseObjectListAdapter;
import com.zoke.support.image.ShowImagesAdapter.AdaterListener;
import com.zoke.support.utils.ViewHolder;

public class SearchAdapter extends BaseObjectListAdapter {

	private AdaterListener listen;

	public SearchAdapter(Context context, List<? extends Object> datas) {
		super(context, datas);
	}

	public SearchAdapter(Context context, List<? extends Object> datas,
			AdaterListener listen) {
		super(context, datas);
		this.listen = listen;
	}

	@Override
	public View getItemView(int position, View convertView, ViewGroup parent) {
		convertView = getConvertView(convertView, R.layout.listview_search_item);
		View view = ViewHolder.get(convertView, R.id.itemContainer);
		final int pos = position;
		final Address ad = (Address) mDatas.get(pos);
		view.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				//
				if (listen != null)
					listen.onAdapterItemClick(pos, ad);
			}
		});
		TextView mTitleTv = ViewHolder.get(convertView, R.id._carpool_title);
		TextView mDesTv = ViewHolder.get(convertView, R.id._carpool_pnum_tv);
		mTitleTv.setText(ad.getTitle());
		mDesTv.setText(ad.getAddress());
		return convertView;
	}

}
